<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>甲供件-原料库出入库综合查询</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="odaProCode"
                                           class="form-control" id="odaProCode"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="odaProName"
                                           class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>供应商</label>
                                    <input type="text" name="supplier" id="supplier"
                                           class="form-control"
                                           placeholder="请输入供应商">
                                </div>
                                <div class="form-group">
                                    <label>合同编号</label>
                                    <input type="text" name="contractNo" id="contractNo"
                                           class="form-control"
                                           placeholder="请输入合同编号">
                                </div>
                                <div class="form-group">
                                    <label>单据编号</label>
                                    <input type="text" name="odrCode" class="form-control"
                                           placeholder="请输入单据编号">
                                </div>
                                <div class="form-group">
                                    <label>跟踪号</label>
                                    <input type="text" name="odaTrackCode" class="form-control"
                                           placeholder="请输入跟踪号">
                                </div>
                                <div class="form-group">
                                    <label>原料类型</label>
                                    <input type="text" name="matTypeName" class="form-control"
                                           placeholder="请输入原料类型">
                                </div>
                                <div class="form-group">
                                    <label>原料材质</label>
                                    <input type="text" name="matQualityName" class="form-control"
                                           placeholder="请输入原料材质">
                                </div>
                                <div class="form-group">
                                    <label>原料规格</label>
                                    <input type="text" name="matSpecName" class="form-control"
                                           placeholder="请输入原料规格">
                                </div>
                                <div class="form-group">
                                    <label>宽度</label>
                                    <input type="number" step="0.1" name="matWidth"
                                           class="form-control"
                                           placeholder="请输入原料宽度">
                                </div>
                                <div class="form-group">
                                    <label>长度</label>
                                    <input type="number" step="0.1" id="materialLengthQuery"
                                           name="matLength" class="form-control"
                                           placeholder="请输入原料长度">
                                </div>
                                <div class="form-group">
                                    <label>米重/厚度</label>
                                    <input type="number" step="0.1" id="materialHeightQuery"
                                           name="matHeight" class="form-control"
                                           placeholder="请输入原料米重/厚度">
                                </div>
                                <div class="form-group">
                                    <label>部门</label>
                                    <input type="text" name="odrTakeWorkshop" class="form-control"
                                           placeholder="请输入部门">
                                </div>
                                <div class="form-group">
                                    <label>制单人</label>
                                    <input type="text" name="odrMakePerson"
                                           class="form-control"
                                           placeholder="请输入制单人">
                                </div>
                                <!--<div class="form-group">-->
                                    <!--<label>库位</label>-->
                                    <!--<select id="whiIdList" name="whiIdList"-->
                                            <!--class="form-control selectpicker"-->
                                            <!--data-live-search="true" multiple>-->
                                        <!--<option th:each="type:${warehouse}" th:value="${type.whiId}"-->
                                                <!--th:text="${type.whiName}"-->
                                                <!--th:selected="${type.whiName eq '原材料甲供件库'}"></option>-->
                                    <!--</select>-->
                                <!--</div>-->
                                <div class="form-group" style="margin-right: 10px; margin-bottom: 5px">
                                    <label>仓库</label>
                                    <select id="ityWhiId" name="ityWhiId" class="selectpicker" multiple
                                            data-actions-box="true"
                                            style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: auto!important;">
                                        <option th:if="${title} == null" selected="selected"
                                                th:each="warehouseInfo:${warehouse}"
                                                th:value="${warehouseInfo.whiId}"
                                                th:text="${warehouseInfo.whiName}"></option>

                                    </select>
                                    <input type="hidden" style="display: none" name="ityWhiIds"/>
                                </div>
                                <div class="form-group">
                                    <label>区位</label>
                                    <input type="text" name="odaPosition"
                                           class="form-control"
                                           placeholder="请输入区位">
                                </div>
                                <div class="form-group">
                                    <label>出入库类型</label>
                                    <select name="inOutType" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="1">入库</option>
                                        <option value="2">出库</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>单据类型</label>
                                    <select name="odrType" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="1">采购入库</option>
                                        <option value="2">退料入库</option>
                                        <option value="4">领料出库</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>
                                        原料分类
                                    </label>
                                    <select name="materialKind" class="form-control ">
                                        <option value="" selected="selected">全部</option>
                                        <option value="型材">型材</option>
                                        <option value="板材">板材</option>
                                        <option value="其他">其他</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>出入库日期</label>
                                    <input type="text" class="form-control datepicker"
                                           name="startOdrDate" id="startOdrDate"
                                           readonly="readonly"/>
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker"
                                           name="endOdrDate" id="endOdrDate"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="row" id="toolbar">
                    <div class="form-inline">
                        <button type="button" id="btn_exportExcel"
                                class="btn btn-primary">
                            导出
                        </button>
                        <img th:src="@{/img/downloadding.gif}" id="btn_tips" style="display: none"/>
                    </div>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" style="word-break:break-all; word-wrap:break-all;"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table;

    /**
     * 设置默认时间
     *
     */
    function getNowMonthDate() {
        var date = new Date();
        var year = date.getFullYear() + "";
        var month = (date.getMonth() + 1) + "";
        var date = date.getDate();
        // 本月第一天日期
        var begin = year + "-" + month + "-1";
        // 本月最后一天日期
        var lastDateOfCurrentMonth = new Date(year,month,0);
        var end = year + "-" + month + "-" + lastDateOfCurrentMonth.getDate();
        // 当日
        var now = year + "-" + month + "-" + date;
        $("#startOdrDate").val(begin);
        $("#endOdrDate").val(now);
    }
    function init() {
        $("#ityWhiId .actions-btn bs-deselect-all btn btn-default").trigger('click');
        $("#ityWhiId .actions-btn actions-btn bs-select-all btn btn-default").trigger('click');
        $("#ityWhiId").trigger('change');
        let ids = "";
        $("#ityWhiId option").each(function () {
            ids += $(this).val() + ",";
        })
        ids = ids.substring(0, ids.length - 1);
        $("#queryForm [name='ityWhiIds']").val(ids);
    }

    /**
     * 仓库改变事件
     */
    $("#ityWhiId").on('change', function () {
        $("#queryForm input[name='ityWhiIds']").val($("#ityWhiId").val());
    });
    function inv(){
        table = js.table.init({
            url: ctx + "materialAccountQuery/list",
            showColumns: true,
            showExport: false,
            queryData: {whiIdLists:$("#ityWhiId").val()},
            columns: [
                {
                    title: '序号', field: 'odaId', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '单据编号', field: 'odrCode', width: '80'},
                {
                    title: '单据类型', field: 'odrType', width: '90',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '采购入库';
                        } else if (value === 2) {
                            return '退料入库';
                        } else if (value === 4) {
                            return '领料出库';
                        }else if (value === 5) {
                            return '调拨出库';
                        } else if (value === 6) {
                            return '调拨入库';
                        }
                    }
                },
                {title: 'SAP物料编码', field: 'odaMatSapCode', width: '80'},
                {title: '类型', field: 'matTypeName', width: '80'},
                {title: '材质', field: 'matQualityName', width: '60'},
                {title: '规格', field: 'matSpecName', width: '60'},
                {title: '宽度', field: 'matWidth', width: '60'},
                {title: '长度', field: 'matLength', width: '60'},
                {title: '米重/<br>厚度', field: 'matHeight', width: '60'},
                {title: '数量', field: 'odaNum', width: '70'},
                {title:'领料长度(米)',field:'pkMatLength',width:'70',
                    formatter:function (value,row,index) {
                        if(value == undefined || value == null || value == 0){
                            return "--"
                        }else {
                            return value;
                        }
                    }
                },
                {title: '理论<br>重量', field: 'odaWeight', width: '80'},
                {title: '跟踪号', field: 'odaTrackCode', width: '95'},
                {title: '项目编号', field: 'odaProCode', width: '80'},
                {title: '项目名称', field: 'odaProName', width: '240'},
                {title: '供货商', field: 'supplier', width: '200'},
                {title: '合同编号', field: 'contractNo', width: '200'},
                {title: '特殊说明', field: 'odaSpec', width: '85'},
                {title: '出入库日期', field: 'odrDate', width: '90'},
                {title: '部门', field: 'odrTakeWorkshop', width: '90'},
                {title: '制单人', field: 'odrMakePerson', width: '60'},
                {title: '单据摘要', field: 'odrRemarkPrint', width: '60'},
                {title: '库位', field: 'odrWhiName', width: '60'},
                {title: '区位', field: 'odaPosition', width: '60'},
                {
                    title: "操作", width: '80',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a target="_blank" class="btn btn-info btn-xs" style="margin-right: 5px" href="' + ctx + 'materialAccountQuery/view?odrId=' + row.odrId + '&odrType=' + row.odrType + '" >查看</a>');
                        return actions.join('');
                    }
                }
            ],
            /*onLoadSuccess: function () {
                if (!hasP("matwar:amount:view")) {
                    table.bootstrapTable('hideColumn', 'odaPrice');
                    table.bootstrapTable('hideColumn', 'odaAmount');
                }
            },*/
            rowStyle: function (row, index) {
                if (row.odaRedFlag === 2) {
                    return {css: {"color": "red"}}
                } else {
                    return {css: {"color": "black"}}
                }
            }
        });
    }
    $(function () {
        getNowMonthDate();
        init();
        /**
         * 加载列表
         */
        table = js.table.init({
            url: ctx + "materialAccountQuery/list",
            showColumns: true,
            showExport: false,
            queryData: {odaRedFlag: 1},
            columns: [
                {
                    title: '序号', field: 'odaId', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '单据编号', field: 'odrCode', width: '80'},
                {
                    title: '单据类型', field: 'odrType', width: '90',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '采购入库';
                        } else if (value === 2) {
                            return '退料入库';
                        } else if (value === 4) {
                            return '领料出库';
                        }else if (value === 5) {
                            return '调拨出库';
                        } else if (value === 6) {
                            return '调拨入库';
                        }
                    }
                },
                {title: 'SAP物料编码', field: 'odaMatSapCode', width: '80'},
                {title: '类型', field: 'matTypeName', width: '80'},
                {title: '材质', field: 'matQualityName', width: '60'},
                {title: '规格', field: 'matSpecName', width: '60'},
                {title: '宽度', field: 'matWidth', width: '60'},
                {title: '长度', field: 'matLength', width: '60'},
                {title: '米重/<br>厚度', field: 'matHeight', width: '60'},
                {title: '数量', field: 'odaNum', width: '70'},
                {title:'领料长度(米)',field:'pkMatLength',width:'70',
                formatter:function (value,row,index) {
                    if(value == undefined || value == null || value == 0){
                        return "--"
                    }else {
                        return value;
                    }
                }
                },
                {title: '理论<br>重量', field: 'odaWeight', width: '80'},
                {title: '跟踪号', field: 'odaTrackCode', width: '95'},
                {title: '项目编号', field: 'odaProCode', width: '80'},
                {title: '项目名称', field: 'odaProName', width: '240'},
                {title: '供货商', field: 'supplier', width: '200'},
                {title: '合同编号', field: 'contractNo', width: '200'},
                {title: '特殊说明', field: 'odaSpec', width: '85'},
                {title: '出入库日期', field: 'odrDate', width: '90'},
                {title: '部门', field: 'odrTakeWorkshop', width: '90'},
                {title: '制单人', field: 'odrMakePerson', width: '60'},
                {title: '单据摘要', field: 'odrRemarkPrint', width: '60'},
                {title: '库位', field: 'odrWhiName', width: '60'},
                {title: '区位', field: 'odaPosition', width: '60'},
                {
                    title: "操作", width: '80',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a target="_blank" class="btn btn-info btn-xs" style="margin-right: 5px" href="' + ctx + 'materialAccountQuery/view?odrId=' + row.odrId + '&odrType=' + row.odrType + '" >查看</a>');
                        return actions.join('');
                    }
                }
            ],
            /*onLoadSuccess: function () {
                if (!hasP("matwar:amount:view")) {
                    table.bootstrapTable('hideColumn', 'odaPrice');
                    table.bootstrapTable('hideColumn', 'odaAmount');
                }
            },*/
            rowStyle: function (row, index) {
                if (row.odaRedFlag === 2) {
                    return {css: {"color": "red"}}
                } else {
                    return {css: {"color": "black"}}
                }
            }
        });

        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.destroy(table);
            inv();
            //js.table.search(table);
        });

        /**
         *@Description: 导出
         */
        $("#btn_exportExcel").click(function () {
            // 判断表单数据是否为空,为空不允许导出
            var isAllEmpty = true;
            var t = $('#queryForm').serializeArray();
            $.each(t, function (i, item) {
                if (item['value'] != '') {
                    isAllEmpty = false;
                }
            })
            if (isAllEmpty) {
                $("#odaProCode").focus();
                js.modal.warning("请填写导出筛选条件！");
                return false;
            }
            // 判断如果起始日期不为空，则终止日期必填
            if ($("#startOdrDate").val() != "" && $("#endOdrDate").val() == "") {
                $("#endOdrDate").focus();
                js.modal.warning("请选择导出终止日期！");
                return false;
            }
            $("#btn_exportExcel").hide();
            $("#btn_tips").show();
            js.post({
                url: ctx + "materialAccountQuery/exportExcel",
                data: $("#queryForm").serialize(),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        location.href=ctx + "materialStockQuery/downloadExportExcel/"+result.data;
                    } else {
                        js.modal.warning("导出失败，请联系管理员！");
                    }
                    $("#btn_tips").hide();
                    $("#btn_exportExcel").show();
                }
            })
        });
    });
</script>
</body>
</html>
